<?php
/**
 * Created by openXtiger.
 * User: lunzi
 * Date: 2009-5-31
 * Time: 10:11:25
 * Index Action
 */


function hi_category_list($pid=0,$tradeType='') {
    $m = xt_load('model','categorymodel');
    header('Content-Type: application/json; charset=gb2312');
    echo xt_json_encode($m('findCategoryByPId',$pid,$tradeType));
    return NONE;
}
function hi_category_search() {
    $m = xt_load('model','categorymodel');
    $keyword = xt_get('keyword');
    header('Content-Type: text/html; charset=gb2312');
    xt_set('categorys',$m('findCategoryByKey',$keyword)); 
    xt_set('keyword',$keyword);
    xt_set('t',xt_get('autoType'));
    return 'category_search';
}


function xt_json_encode($a=false) {
    if (is_null($a)) return 'null';
    if ($a === false) return 'false';
    if ($a === true) return 'true';
    if (is_scalar($a)) {
        if (is_float($a)) {
            return floatval(str_replace(",", ".", strval($a)));
        }

        if (is_string($a)) {
            static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));
            return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"';
        }
        else
            return $a;
    }
    $isList = true;
    for ($i = 0, reset($a); $i < count($a); $i++, next($a)){
        if (key($a) !== $i){
            $isList = false;
            break;
        }
    }
    $result = array();
    if ($isList) {
        foreach ($a as $v) $result[] = xt_json_encode($v);
        return '[' . join(',', $result) . ']';
    } else{
        foreach ($a as $k => $v) $result[] = xt_json_encode($k).':'.xt_json_encode($v);
        return '{' . join(',', $result) . '}';
    }
}

?>